# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2023/12/3
desc: 
sample: 
"""
# !/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import division

import gc
import os

'''
功能： 比较python内置的max()和min()方法与numpy提供的max()和min()方法性能差异
'''

import time
import random
import numpy as np


def generateRandomNums(num=1000):
    '''
    生成指定数量的随机数
    '''
    res_list = []
    for i in range(num):
        res_list.append(random.randint(0, 999999999))
    return res_list


def compareTime(res_list):
    '''
    时间效率对比分析
    '''
    T1 = time.time()
    max_num = max(res_list)
    min_num = min(res_list)
    T2 = time.time()
    print('================================')
    print('max_num: ', max_num)
    print('min_num: ', min_num)
    print('time_consume: ', T2 - T1)

    T3 = time.time()
    max_num2 = np.max(res_list)
    min_num2 = np.min(res_list)
    T4 = time.time()
    print('================================')
    print('max_num2: ', max_num2)
    print('min_num2: ', min_num2)
    print('time_consume: ', T4 - T3)


if __name__ == '__main__':
    print(os.getpid())
    time.sleep(10)
    res_list = generateRandomNums(num=5000000)
    time.sleep(10)
    compareTime(res_list)